import axios from '@/api'
import { IGrain, IGetMemberFieldDetail, IPlant } from './famer'
import { ILargePlant } from './largeMember'
import {
  publishStatusEnum
} from '../enum'

export interface IPublish {
  pub_id: string
  s_a_id: string
  s_a_nam_all: string
  pub_title: string
  pub_ck_tel1: string
  pub_ck_u1: string
  pub_ck_start1: string
  pub_ck_end1: string
  pub_ck_state1: publishStatusEnum
  pub_ck_readme1: string
  pub_ck_tel2: string
  pub_ck_u2: string
  pub_ck_start2: string
  pub_ck_end2: string
  pub_ck_state2: publishStatusEnum
  pub_ck_readme2: string
  pub_ck_tel3: string
  pub_ck_u3: string
  pub_ck_start3: string
  pub_ck_end3: string
  pub_ck_state3: publishStatusEnum
  pub_ck_readme3: string
}
export interface IGetPublishList {
  request: Pick<IPublish, 's_a_id'>
  response: Array<IPublish>
}

export interface IPublicMember {
  pub_id: string
  member_id: string
  member_nam: string
  s_a_id: string
  s_a_nam_all: string
  field: string
  field1: string
  field2: string
  field3: string
  plant: string
  pay_price: string
  pay_unit: string
  pay_price_total: string
  bank_num: string
  bank_nam: string
}

class PublishServices {
  constructor() {}

  /**
   * 获取公示信息列表
   *
   * @returns
   * @memberof PublishServices
   */
  async getPublishList(data: IGetPublishList['request']) {
    return axios.post<
      unknown,
      Api.ResponseOptions<IGetPublishList['response']>
    >('/btbusiness/publish/get-publish-list', data)
  }

  /**
   * 编辑公示信息
   *
   * @param {Partial<IPublish>} data
   * @returns
   * @memberof PublishServices
   */
  async updatePublish(data: Partial<IPublish> & { is_big_member?: boolean }) {
    const res = await axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/publish/edit-publish',
      data
    )
    return res
  }

  /**
   * 获取待发布公示人员列表
   *
   * @param {(Pick<IPublish, 'pub_id'> & Api.PageOptions)} data
   * @returns
   * @memberof PublishServices
   */
  previewMembers(data: Pick<IPublish, 'pub_id'> & Api.PageOptions) {
    return axios.post<unknown, Api.ResponseListOptions<IPublicMember[]>>(
      '/btbusiness/publish/get-publish-view',
      data
    )
  }

  /**
   * 获取公示人员列表
   *
   * @param {Pick<IPublish, 'pub_id'>} data
   * @returns
   * @memberof PublishServices
   */
  async getPublishUsers(data: Pick<IPublish, 'pub_id'> & Api.PageOptions) {
    return axios.post<unknown, Api.ResponseListOptions<IGrain[]>>(
      '/btbusiness/publish/get-publish-user-list',
      data
    )
  }

  /**
   * 获取公示家庭耕地信息
   *
   * @param {IGetMemberFieldDetail['request']} data
   * @returns
   * @memberof PublishServices
   */
  async getPublishUserFields(data: IGetMemberFieldDetail['request']) {
    return await axios.post<
      unknown,
      Api.ResponseListOptions<IGetMemberFieldDetail['response']>
    >('/btbusiness/publish/get-publish-user-field', data)
  }

  /**
   * 获取公示家庭种植信息
   *
   * @param {(Pick<IPlant, 'family_id' | 's_a_id'>)} data
   * @returns
   * @memberof PublishServices
   */
  async getPublishUserPlants(
    data: Pick<IPlant, 'family_id' | 's_a_id'> & Pick<IPublish, 'pub_id'>
  ) {
    return await axios.post<unknown, Api.ResponseListOptions<IPlant[]>>(
      '/btbusiness/publish/get-publish-user-plant',
      data
    )
  }

  /**
   * 获取公示大户耕地信息
   *
   * @param {IGetMemberFieldDetail['request']} data
   * @returns
   * @memberof PublishServices
   */
  async getPublishLargeFields(data: IGetMemberFieldDetail['request']) {
    return await axios.post<
      unknown,
      Api.ResponseListOptions<IGetMemberFieldDetail['response']>
    >('/btbusiness/publish/get-publish-big-user-field', data)
  }

  /**
   * 获取公示大户种植信息
   *
   * @param {(Pick<ILargePlant, 'family_id' | 's_a_id'>)} data
   * @returns
   * @memberof PublishServices
   */
  async getPublishLargePlants(
    data: Pick<ILargePlant, 'big_mb_id' | 's_a_id'> & Pick<IPublish, 'pub_id'>
  ) {
    return await axios.post<unknown, Api.ResponseListOptions<ILargePlant[]>>(
      '/btbusiness/publish/get-publish-big-user-plant',
      data
    )
  }

  /**
   * 获取公示大户农资信息
   *
   * @param {{ big_mb_id: string, s_a_id: string; }} data
   * @returns
   * @memberof PublishServices
   */
  getPublishLargeMemberMaterial(
    data: { big_mb_id: string; s_a_id: string } & Pick<IPublish, 'pub_id'>
  ) {
    return axios.post<unknown, Api.ResponseListOptions<ILargePlant[]>>(
      '/btbusiness/publish/get-publish-big-user-material',
      data
    )
  }

  /**
   * 获取公示种粮大户农机信息
   *
   * @param { big_mb_id: string } data
   * @returns
   * @memberof PublishServices
   */
  getPublishLargeMemberMachines(
    data: { big_mb_id: string; s_a_id: string } & Pick<IPublish, 'pub_id'>
  ) {
    return axios.post<unknown, Api.ResponseListOptions<ILargePlant[]>>(
      '/btbusiness/publish/get-publish-big-user-machine',
      data
    )
  }

  /**
   * 导出公示中用户信息
   *
   * @param {Pick<IPublish, 'pub_id'>} data
   * @returns
   * @memberof PublishServices
   */
  exportPublishMemberExecl(data: {
    export_area?: string;
    exportExcelMode?: string;
    pub_id?: string;
    keys: string[]
  }) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/publish/export-publish-user',
      // '/btpub/pub/a',
      data,
      {
        customHandler: true,
        responseType: 'blob'
      }
    )
  }

  /**
   * 撤销区域公示
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof PublishServices
   */
  revokePublic(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/publish/delete-area-publish',
      data
    )
  }
}

export const publishServices = new PublishServices()

export default PublishServices
